home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
INFO
/
DOSTIPS5.ZIP
/
DOSFIND
< prev
next >
Wrap
Text File
|
1986-07-22
|
7KB
|
115 lines
Finding the Files You Want
(Personal Computing August 1986 by Miriam Liskin)
To help you find the needles you want in the haystack of files
you have accumulated, there are fundamentally two types of tools --
utilities that can search any existing text files for a given string
of characters, and programs that index a specified set of files in
advance in preparation for rapid retieval later on. The latter
usually cost money, from a few dollars for a decent public domain
program to quite a few dollars for a commercial utility.
With any computer that runs DOS 2.0 or later, you already own
a program of the first type -- the FIND.EXE utility supplied with the
operating system, and it's already paid for. In its simplest
invocation, this program searches an existing text file for a specified
character string and displays on the screen the lines containing the
search string.
FIND has three parameters that provide additional flexibility.
the /V option displays all the files that do not contain a specified
string. The /C parameter causes FIND to simply count the lines that
contain the desired string, without displaying each one. These options
are primarily intended for programmers. The final option, /N, is more
valuable for ordinary text search requirements. With this parameter
included in the FIND command, line numbers are included in the screen
display, to show you the context of the search string. To display all
the lines with numbers, in a file called AB860815.BRF that contain the
word "liability," you could use the command:
FIND /N "liability" AB860815.BRF
Given its origin as a utility for programmers, it is not unusual
that FIND is more line-oriented that most word processors. You can,
however, use it to search files created by any word processor or text
editor, or in fact any files on your disk, including (although you
would rarely want to do so) .COM or .EXE files.
If your word processor places a carriage return at the end of each
screen line, the single lines of text displayed on the screen may not
fully reveal the context of the search string. With word processors
that use a return only to mark the end of a paragraph, FIND will
consider the entire paragraph to be one line. In this case, or with
word processors that do not number the lines in a file sequentially
(most do not), the actual line numbers displayed by FIND may be of use
only insofar as they indicate the approximate position of the search
string in the file.
Used this way, FIND enables you to determine whether a given file
is the one you want by telling you whether or not it contains the text
you have specified. This is only marginally better than using TYPE to
display the files yourself, but there are a few tricks you can use that
greatly increase the usefulness of this simple program.
You can instruct FIND to search multiple files by including more
than one file name in the command line. The program does not permit
the use of the standard DOS wildcard characters (* and ?), so you must
type all of the file names explicitly, separated by a single space, for
example:
FIND /N "liability" AB860815.BRF AB860820.MOT AB860901.MOT AB860901.LTR
The output of this command consists of the first file name,
followed by all the lines from that file that contain the text
"liability" (with line numbers), then the next file name, and so on.
You can further automate the search process by creating a batch file
containing one or more FIND commands, and optionally, by redirecting
the output of the command to a disk file so that you do not have to
sit at the computer watching the screen. The following batch file
searches six files for the text "liability" and stores the output in
a file called LIABIL.TXT:
FIND /N "liability" AB860815.BRF AB860820.MOT AB860901.MOT > LIABIL.TXT
FIND /N "liability" AB860901.LTR AB860910.LTR AB860912.LTR >> LIABIL.TXT
The output file, LIABIL.TXT, is created by the first FIND command;
using ">>" rather than ">" in the second and subsequent commands causes
the specified output to be appended to this file instead of recreating
it from scratch and thus destroying the prior contents. Using this
approach, you can carry out a lengthy search unattended and examine
the resulting file at your leisure.
Note also that although the two FIND commands in this example
search for the same text, this need not be the case, since they are
separate and independent uses of the FIND program. Also, because FIND
differentiates between upper- and lower-case, you may want to omit the
first letter of a word from the search string -- "iability" instead of
"liability" -- if the word might occur at the beginning of a sentence.
Using these techniques, you can construct a fairly complex search with
a series of FIND commands employing different search strings.
If you have a large number of files to search, you can use another
property of DOS batch files to overcome the limitation on the use of
wild cards in file names supplied as input to the FIND program. The
FOR command, a DOS subcommand permitted only in batch files, permits
the use of variables, written as two "%" signs followed by a letter;
for example, %%F. You can specify a set of values to be substituted
in turn for the variable name, and if the variable represents a file
name, you may use wild cards. The basic form of the FOR command is:
FOR <condition> DO <command>
To repeat the same FIND command for each file that matches the
pattern AB*.*, and save the output in a file called LIABIL.TXT, you
could use the following in a batch file:
FOR %%F IN (AB*.*) DO FIND /N "liability" %%F >> LIABIL.TXT
This command searches for all of the file names that match AB*.*.
Each is substituted in turn for the variable name %%f, and the
resulting FIND command is carried out. If you need to search more
than one group of files, you can include lines of this form in one
batch file.
FIND.EXE, which is readily available on your DOS disk and will
cost you nothing, is adequate for the infrequent searches occasioned
by forgetting which of a set of files contains the material you want.
If you need to carry out this kind of search and retrieval more often
-- for example, to gather material from previous documents for reports
or research projects -- there are programs that give you far more power
and flexibility.